import xml.etree.cElementTree as etree


class ScheduleStore(object):
	def __init__(self):
		pass
	def read(self):
		pass
	def write(self, sched):
		root = etree.Element('schedule')
		for sesn in sched:
			elem = etree.SubElement(root, 'session')
			def add_elem(attr):
				etree.SubElement(elem, attr).text = getattr(sesn, attr)
			add_elem('name')
			add_elem('file')
			add_elem('title')
			add_elem('recur')
			add_elem('start')
			add_elem('stop')
			add_elem('evtid')
			add_elem('editurl')
			for owner in sesn.owners:
				subelem = etree.SubElement(elem, 'owner')
				add_xmltext(subelem, owner, 'name')
				add_xmltext(subelem, owner, 'email')
			for section in sorted(sesn.sections):
				add_foo(elem, section, 'section')
			for link in sorted(sesn.links):
				add_foo(elem, link, 'link')


			etree.SubElement(elem, 'name').text = sesn.name
			etree.SubElement(elem, 'title').text = sesn.title
			etree.SubElement(elem, 'recur').text = sesn.recur
